package com.res.share.common.seo;

import java.util.ArrayList;
import java.util.List;

public class AISeoArticle {

    /**
     * 文章长度边界
     */
    public static final int MAX_LENGTH = 2000;

    /**
     * 句号, 切割标准
     */
    public static final String PERIOD = "。";


    /**
     * 将文章进行切割
     *
     * @param article 文章
     */
    public static List<String> sliceArticle(String article) {
        List<String> sentenceList = new ArrayList<>();
        // 超过范围, 进行切割
        if (article.length() > MAX_LENGTH) {
            // 将文章全部切割成句子
            String[] sentences = article.split(PERIOD);
            // 获取句子总数
            int len = sentences.length;
            // 计数器
            int count = 0;
            // 计算总数
            int title = 0;
            // 段落拼接
            StringBuilder sb = new StringBuilder();
            for (String sentence : sentences) {
                sb.append(sentence);
                if (count == 10) {
                    // 存储切分的段落
                    sentenceList.add(sb.toString());
                    // 重新赋值
                    sb = new StringBuilder();
                    // 计数器清零
                    count = 0;
                }
                if (title == len) {
                    sentenceList.add(sb.toString());
                }
                title++;
                count++;
            }
        } else {
            sentenceList.add(article);
        }
        return sentenceList;
    }

}
